﻿@page "/Account/Logout"
@inject NavigationManager NavigationManager
@using Microsoft.AspNetCore.WebUtilities
@using IdentityServer4Blazor.Shared.IdentityServerModel
@layout EmptyLayOut
<h3>@content</h3>

@code {
    string content = "正在登出。。。。。。";
    protected override async Task OnInitializedAsync()
    {
        Console.WriteLine("logout");
        var logoutId = Common.ReuseMethod.GetUrlQuery(NavigationManager.Uri,"logoutId");
        Console.WriteLine(logoutId);
        var res = await Http.PostAsJsonAsync("/api/Account/Logout", new LogoutInputModel { LogoutId = logoutId });
        Console.WriteLine(res.Data.ToString());
        var model =  JsonSerializer.Deserialize<LoggedOutViewModel>(res.Data.ToString());
        Console.WriteLine(model.PostLogoutRedirectUri);
        if (res.Success)
        {
            if (model.AutomaticRedirectAfterSignOut)
            {
                content = "登出成功！正在跳转！";
                Console.WriteLine(model.PostLogoutRedirectUri);
                NavigationManager.NavigateTo(model.PostLogoutRedirectUri);
            }
        }
    }
}
